package com.leyou.item.web;


import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/category")
public class CategoryController {

    private final CategoryService categoryService;

    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }


    /**
     * 根据分类Id查询对应的分类对象，返回分类的dto
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> findCategoryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.categoryService.findCategoryById(id));
    }


    /**
     * 根据分类id集合查询分类集合
     * @param ids
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>>
    listCategoryById(@RequestParam("ids") List<Long> ids) {
        return ResponseEntity.ok(this.categoryService.listCategoryById(ids));
    }

    /**
     * 根据父类目id，查询子类目的集合
     * @param pid
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>>
    listCategoryParent(@RequestParam("pid") Long pid) {
        return ResponseEntity.ok(this.categoryService.listCategoryParent(pid));
    }

    /**
     * 根据品牌id，查询商品分类的集合
     * @param bid
     * @return
     */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>>
    listCategoryBrand(@RequestParam("id") Long bid) {
        return ResponseEntity.ok(this.categoryService.listCategoryBrand(bid));
    }
}
